﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GameSchool.Models.Interfaces;

namespace GameSchool.Models.Repositories
{
    public class HandInRepository : IHandInRepository
    {
        GameSchoolDBDataContext db = new GameSchoolDBDataContext();

        public void AddHandIn(HandIn h)
        {
            db.HandIns.InsertOnSubmit(h);    
        }

        //Fetches all HandIns
        public IQueryable<HandIn> GetHandIn()
        {
             return db.HandIns;
        }

        //Fetches a single HandIn by it's ID
        public HandIn GetHandInByID(int? hID)
        {
            var hand = (from HandIn in db.HandIns
                       where HandIn.ID == hID
                       select HandIn).SingleOrDefault();

            return hand;
        }

        //Deletes a HandIn by it's ID
        public void DeleteHandIn(int? hID)
        {
            var hand = (from HandIn in db.HandIns
                        where HandIn.ID == hID
                        select HandIn).SingleOrDefault();

            if (hand != null)
            {
                db.HandIns.DeleteOnSubmit(hand);
            }
        }

        public void Save()
        {
            db.SubmitChanges();
        }
    }
}